﻿using System.Collections.Concurrent;
using Fetches.Fetch.Dto;

namespace Fetches.Fetch.PagePool
{
    public class InMemoryPagePool : LocalPagePool
    {
        private readonly ConcurrentDictionary<string, ResponsePage> _pages = new ConcurrentDictionary<string, ResponsePage>();

        public override ResponsePage Get(int offset)
        {
            return PagesIndex.TryGetValue(offset,out var pageId) ? Get(pageId) : null;
        }

        protected override void Store(ResponsePage responsePage)
        {
            _pages.TryAdd(responsePage.Id, responsePage);
        }

        public override ResponsePage Get(string pageId)
        {
            return _pages.TryGetValue(pageId, out var page) ? page : null;
        }

    }
}
